package The15;

import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashSet;
import java.util.List;

/**
 * @Author XiaoKe
 * @Date 2020/4/29 17:34
 * @Description 操作文件的工具类
 */
public class FilesTest {
    public static void main(String[] args) throws Exception {
        // 复制文件
        Files.copy(Paths.get("D:\\IdeaWorkspace1\\CrazyJavaDemo\\src\\main\\java\\The15\\FilesTest.java"),
                new FileOutputStream("D:\\IdeaWorkspace1\\CrazyJavaDemo\\src\\main\\java\\The15\\a.txt"));
        // 一次性读取文件所有行
        List<String> lines = Files.readAllLines(Paths
                .get("D:\\IdeaWorkspace1\\CrazyJavaDemo\\src\\main\\java\\The15\\FilesTest.java"));
        HashSet<String> books = new HashSet<>();
        books.add("java");
        books.add("c++");
        // 直接将多个字符串写入指定文件
        Path write = Files.write(Paths.get("D:\\IdeaWorkspace1\\CrazyJavaDemo\\src\\main\\java\\The15\\b.txt"), books);

    }
}
